package com.gxa.p2p.service.impl;

import com.gxa.p2p.mapper.FeedbackMapper;
import com.gxa.p2p.pojo.Feedback;

import com.gxa.p2p.service.FeedbackService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 意见操作业务层
 * @author HS
 */

@Transactional(rollbackFor = {Throwable.class})
@Service("feedbackService")
public class FeedbackServiceImpl implements FeedbackService {

    @Autowired
    private FeedbackMapper mapper=null;

    @Override
    public Feedback findFeedbackById(Long id) {
        return mapper.findFeedbackById(id);
    }

    @Override
    public Map<Integer,List<Feedback>> findFeedbackByPage(Map map) {

        //得到查询数据
        Boolean state=null;

        if(map.get("state")!=null&&!map.get("state").toString().equals("")){

            state=Boolean.valueOf(map.get("state").toString());

        }

        map.put("state",state);

        Integer page = Integer.parseInt(map.get("page").toString()) ;
        Integer size = Integer.parseInt(map.get("size").toString());


        map.put("page",(page-1)*size) ;
        map.put("size",size) ;
        List<Feedback> resultList= mapper.findFeedbackByPage(map);
        //得到数据总数count
        map.put("size",null);
        map.put("page",null);

        Integer count = mapper.findFeedbackByPage(map).size();

        Map<Integer,List<Feedback>> resultMap=new HashMap<>();
        resultMap.put(count,resultList);

        return resultMap;
    }

    @Override
    public void updateFeedback(Map map) {

        Long id = Long.valueOf(map.get("id").toString());

        map.put("id",id);
        Boolean state =Boolean.valueOf(map.get("state").toString()) ;
        map.put("state",state);

        map.put("subTime",new Timestamp(System.currentTimeMillis()));

        mapper.updateFeedback(map);
    }
}
